package com.acceptable.qucun.generic.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class MessageUtil {

    private static String sender = "【趣存开发者：巴斯罗斯·K·赫斯洛利】";
    private static String verifyTitle = "【趣存】-- operation验证码";
    private static String verifyContent = "亲爱的用户：您好！您的账号（email）正在进行operation。\n" +
            "本次operation的验证码为：verifyCode。\n该验证码5分钟内有效，请于expireTime之前完成验证。";
    private static String tipTitle = "【趣存】 -- operation提醒";
    private static String tipContent = "亲爱的用户：您好！您的账号（email）已完成operation。";

    private static Map<String, String> operationMap = new HashMap<>();

    public static Map<String, String> getOperationMap() {
        operationMap.put("login", "登录");
        operationMap.put("register", "注册");
        operationMap.put("reset_pwd", "重置密码");
        operationMap.put("change_pwd", "修改密码");
        operationMap.put("physical_delete", "物理删除");
        operationMap.put("change_email", "邮箱换绑");
        operationMap.put("drop_account", "注销帐号");
        return operationMap;
    }

    public static String createMessage(String type, Map<String, String> wordMap){
        String content = verifyContent;
        StringBuilder builder = new StringBuilder();
        if("tip".equals(type))
            content = tipContent;
        for (Map.Entry<String, String> entry: wordMap.entrySet()){
            String key = entry.getKey();
            String value = entry.getValue();
            content = content.replace(key, value);
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String sendDate =  sdf.format(new Date());

        content = content.concat("\n" + sender + "\n")
                         .concat(sendDate);
//        System.out.println(content);
        return content;
    }

    public static String createTitle(String type, String operation){
        String title = verifyTitle;
        if("tip".equals(type))
            title = tipTitle;

        return title.replace("operation", operation);
    }
}
